﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Linq.Expressions;

namespace Northwinddemo.BusinessLayer.Models
{
    public static class ExpressHelper
    {

        // http://beta.blogs.microsoft.co.il/blogs/smallfish/archive/2009/04/02/how-to-get-a-property-name-using-lambda-expression-in-c-3-0.aspx
        public static string GetPropertyName<T>(Expression<Func<T, object>> property)
        {
            var propertyInfo = (property.Body as MemberExpression).Member;
            if (propertyInfo == null)
            {
                throw new ArgumentException("The lambda expression 'property' should point to a valid Property");
            }
            var propertyName = propertyInfo.Name;

            return propertyName;
        }
    }
}
